<layout name="page" />
<block name="content">
    <style>
        .sub-sidebar {
            height: 500px;
            overflow-y: scroll;
        }
    </style>
    {:widget('page_header/search',array('name'=>'权限设置','search'=>'S'))}
    <div class="operate-panel">
        <div class="x-panel-body">
            <div class="pull-right">
                <a id="btn_save" class="btn">保存</a>
            </div>
        </div>
    </div>
    <!-- 列表显示区域  -->
    <div class="row">
        <form id="form_data" name="form_data" method="post">
            <div class="col-sm-8 sub-sidebar">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th class="text-center col-4">
                                <label class="inline pull-left">
                                    <input  type="checkbox"class="toggle-select-all" />
                                </label>
                            </th>
                            <th>
                                <nobr>
                                    员工编号
                                </nobr>
                            </th>
                            <th>
                                <nobr>
                                    姓名
                                </nobr>
                            </th>
                            <th>
                                <nobr>
                                    部门
                                </nobr>
                            </th>
                            <th class="hidden">
                                <nobr>
                                    职级
                                </nobr>
                            </th>
                            <th>
                                <nobr>
                                    职位
                                </nobr>
                            </th>
                            <th>
                                <nobr>
                                    状态
                                </nobr>
                            </th>
                        </tr>
                    </thead>
                    <tbody class="tbody">
                        <volist name="user_list" id="data">
                            <tr id="{$data.id}">
                                <td class="text-center col-3">
                                    <label class="inline pull-left">
                                        <input  type="checkbox" name="emp_id[]" value="{$data.id}" />
                                    </label>
                                </td>
                                <td>
                                    <nobr>
                                        {$data.emp_no}
                                    </nobr>
                                </td>
                                <td>
                                    <nobr>
                                        {$data.name}
                                    </nobr>
                                </td>
                                <td>
                                    <nobr>
                                        {$data.dept_name}
                                    </nobr>
                                </td>
                                <td>
                                    <nobr>
                                        {$data.position_name}
                                    </nobr>
                                </td>
                                <td>
                                    <nobr>
                                        {$data.is_del|status}
                                    </nobr>
                                </td>
                            </tr>
                        </foreach>
                    </tbody>
                </table>
            </div>
            <div class="col-sm-4 sub-content">
                <input type="hidden" name="id" id="id"><input type="hidden" name="pid" id="pid" value=""><input type="hidden" name="ajax" id="ajax" value="0"><input type="hidden" name="opmode" id="opmode" value="">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>
                                &nbsp;
                            </th>
                            <th>
                                名称
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <volist name="role_list" id="data">
                            <tr id="{$data.id}">
                                <td class="col-4">
                                    <label >
                                        <input  type="radio" id="role_{$data.value}" name="role_list[]" value="{$data.value}"/>
                                    </label>
                                </td>
                                <td>
                                    {$data.name}
                                </td>
                            </tr>
                        </foreach>
                    </tbody>
                </table>
            </div>
        </form>
    </div>
</block>
<block name="js">
    <script type="text/javascript">
        function btn_search(){
            send_form("form_search", "__SELF__");
            $("#form_search").submit();
        }
        
        function key_search(){
            if (event.keyCode == 13) {
                send_form("form_search", "__SELF__");
                return false;
            }
        }
        
        function save(){
            if ($("input:checked[name='emp_id[]']").length < 1) {
                ui_error("请选择用户");
                return false;
            };
            if ($("input:checked[name='role_list[]']").length < 1) {
                ui_error("请选择权限");
                return false;
            };
			var vars = $("#form_data").serialize();
			send_ajax("{:url('set_role')}", vars, function(data){
               if (data.status) {
						ui_alert(data.info, function() {
							parent.location.reload(true);
							myclose();
						});
					} else {
						ui_error(data.info);
					}
                });
        }
        
        function show_data(data){
            $("input[name='role_list[]']").each(function(){
                $(this).prop('checked', false);
            });
            for (var i=0;i<data.set_auth.length;i++) {
                $("#role_" +data.set_auth[i]).prop('checked', true);
            }
        }
        
        
        $(document).ready(function(){
            set_return_url(null);
            $(".sub-sidebar tbody tr").click(function(){
                $(".sub-sidebar  tr").attr("class", "");
                $(this).attr("class", "active");
                send_ajax("{:url('get_role_list')}", "id=" + $(this).attr("id"), function(data){
                    show_data(data);
                });
            });
        });
    </script>
</block>
